<?php

require_once('interfaces/RequestMapping.interface.php');
require_once('classes/Mapping/AbstractMappingConfig.class.php');

class NaturalMappingConfig extends AbstractMappingConfig implements RequestMapping{

    private $to;

    public function NaturalMappingConfig(){
    }

    public function checkMapping($uri){
        if (!$this->configObj->conditionsMet()){
            return false;
        }
        if (file_exists($file = $_SERVER['DOCUMENT_ROOT'].$uri)){
            $this->to = $file;
            return true;
        }else{
            return false;
        }
        // TODO: Include some of the following logic to have variable extentions for static files
        $extArray = $this->parent->getDynamicExtention();
        if (!is_array($extArray) || count($extArray) == 0){
            $extArray = array('');
        }
        foreach ($extArray as $ext){
            if (file_exists($file = $_SERVER['DOCUMENT_ROOT'].$uri.$ext)){
                $this->to = $file;
                return true;
            }
        }
        return false;
    }

    public function run(){
        $this->configObj->run();
        $this->includeFile($this->to);
    }

    public static function getXsdPart(){
        return '';
    }

    public static function interpretXmlConfig(/*XMLNodeList?*/ $item, /*RequestInterpreter*/ $interpreter){
        $name = $item->localName;
        $interpreter->addMapping(new $name());
    }

}

?>